var express = require('express');
var home_router = express.Router();
let Articles = require("../mongodb/mongodb").Articles //引入数据库模型

// 处理post请求的中间件，用于解析post返回的数据
const bodyParser = require('body-parser')
home_router.use(bodyParser.urlencoded({
  extended: false
}))
/* GET users listing. */
home_router.get('/article', function(req, res, next) {
  let DB = Articles;
  let page = req.query.page;
  console.log("页码："+page)
  DB.find().skip((page-1)*10).limit(6).exec(function(err,docs){
    if(err){
      console.log(err)
      console.log("错误");
      res.send({
        status:300,
        msg:'暂时没有新的数据'
      })
    }else{
      res.send(docs)
    }
  })
  
});

module.exports = home_router;
